package view.Professeurs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import view.Fenetre;
import view.Param;

import Controller.ExerciceController;
import Controller.ProfesseurController;

@SuppressWarnings("serial")
public class ExosDelPanel extends JPanel implements ActionListener {

	private ArrayList<JCheckBox> cList;
	private JButton bRemove;

	public ExosDelPanel() {

		// Alignement vertical des conteneurs
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		// Creation des conteneurs
		JLabel lNomExo = new JLabel("Liste des exercices : ");
		JPanel pList = new JPanel();
		cList = new ArrayList<JCheckBox> ();
		bRemove = new JButton("Supprimer");
		
		ExerciceController exc = Fenetre.control.getExerciceController();
		ProfesseurController cProf = Fenetre.control.getProfesseurController();
		
		// Creation de l'arborescence des themes
		ArrayList<String> themes = exc.listeTheme();								// liste des themes
		ArrayList<ExerciceController> exercices = new ArrayList<ExerciceController> ();					// liste des exercices
		DefaultMutableTreeNode root = new DefaultMutableTreeNode();					// noeud racine
		DefaultMutableTreeNode node = null;											// noeud principal
		DefaultMutableTreeNode node2 = null;										// noeud secondaire
		JTree tree = null;															// arbre de noeuds
		
		// Ajout de la transparence
		this.setOpaque(false);
		pList.setOpaque(false);

		// Ajout des conteneurs
		this.add(lNomExo);
		
		// Ajustements du panel liste
		pList.setLayout(new BoxLayout(pList, BoxLayout.Y_AXIS));
		
		for (int i=0; i<themes.size(); i++) {
			
			// Affichage du nom du theme sur le noeud principal
			node = new DefaultMutableTreeNode(themes.get(i));
			
			exercices = cProf.getListExercice(themes.get(i));
			
			for (int j=0; j<exercices.size(); j++) {
				
				// Affichage des noms des exercices
				node2 = new DefaultMutableTreeNode(exercices.get(i));
				node.add(node2);
				
			}
			
			root.add(node);
			
		}
		
		tree = new JTree(root);
		tree.setOpaque(false);
		
		pList.add(tree);
		
		this.add(pList);
		this.add(bRemove);
		
		// Ajout des marges
		pList.setBorder(Param.wideMargin);

		// Ajout des ecouteurs
		bRemove.addActionListener(this);

	}

	@Override
	public void actionPerformed(ActionEvent event) {



	}

}
